<template>
  <div class="index-announcement">
    <div class="index-announcement-table-box">
      <page-container class="left">
        <el-form inline>
          <el-form-item style="max-width:864px">
            <el-input v-model="params.title" placeholder="请您输入公告标题" style="width: 100%; margin: 20px 0 20px 10px;" />
          </el-form-item class="announcement-header">
          <el-form-item>
            <el-button type="primary" plain @click="onSearch">搜索</el-button>
            <el-button type="info" plain @click="onReset">重置</el-button>
          </el-form-item>
        </el-form>
        <!-- 表格 -->
        <el-table :data="announcementList" height="580px" style="width: 100%">
          <el-table-column align="center" width="100px" label="序号">
            <template #default="{ $index }">
              {{ (params.pageNum - 1) * params.pageSize + $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column align="left" prop="title" :show-overflow-tooltip="true" label="公告标题" />
          <!-- <el-table-column align="center" prop="creatorName" :show-overflow-tooltip="true" label="发布人" /> -->
          <el-table-column align="right" prop="createTime" :show-overflow-tooltip="true" label="发布时间" />
          <el-table-column label="操作" align="center" width="180px">
            <template #default="{ row }">
              <el-button type="text" plain  @click="goAnnouncementDetails(row.announcementId)">
                详情
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页区域 -->
        <el-pagination background layout="total, sizes, prev, pager, next, jumper" :total="total"
          v-model:current-page="params.pageNum" v-model:page-size="params.pageSize" :page-sizes="[5, 10, 15, 20]"
          @size-change="handleSizeChange" @current-change="handleCurrentChange"
          style="margin:20px 100px 20px 0; justify-content: flex-end" />
      </page-container>
      <div class="right">
        <div class="top-box">
          <el-calendar v-model="today"> </el-calendar>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref } from "vue"
import { getAnnouncementListService } from '@/apis/announcement'
// import { getToken } from "@/utils/cookie" //用于判断当前用户是否登录，有些页面是允许游客访问的
import router from "@/router"
// import { getUserInfoService } from "@/apis/user"

const params = reactive({
  pageNum: 1,
  pageSize: 10,
  title: '',
})
let today = ref(new Date()) //日历默认今天
const announcementList = ref([]) //题目列表
const total = ref(0)
// const isLogin = ref(false)

// async function checkLogin() {
//   if (getToken()) {
//     await getUserInfoService()
//     isLogin.value = true
//   }
// }
// checkLogin()

async function getAnnouncementList() {
  const result = await getAnnouncementListService(params)
  announcementList.value = result.rows
  total.value = result.total
}
getAnnouncementList()

// 搜索/重置
function onSearch() {
  params.pageNum = 1
  getAnnouncementList()
}

function onReset() {
  params.pageNum = 1
  params.pageSize = 9
  params.title = ''
  getAnnouncementList()
}

// 分页
function handleSizeChange(newSize) {
  console.log(params.pageSize)
  params.pageNum = 1
  getAnnouncementList()
}

function handleCurrentChange(newPage) {
  getAnnouncementList()
}

function goAnnouncementDetails(announcementId) {
  // 取详情页面
  router.push(`/tims/announcementDetails?announcementId=${announcementId}`)
}
</script>

<style lang="scss" scoped>
.index-announcement-table-box {
  display: flex;
  max-width: 1520px;
  width: 100%;
  justify-content: space-between;

  :deep(.el-pagination) {

    .el-select .el-select__wrapper,
    .el-input .el-input__wrapper {
      height: 24px;
    }
  }

  .right {
    width: 340px;

    :deep(.top-box) {
      width: 100%;
      height: 345px;
      padding-bottom: 20px;
      margin-bottom: 20px;
      border-radius: 16px;
      background: linear-gradient(164deg, #E2F7FF 0%, #FFFFFF 50%);

      .el-calendar,
      .el-calendar__body {
        background: transparent;
      }

      .el-calendar {
        position: relative;

        .el-calendar__title {
          font-weight: bold;
        }

        .el-calendar__header {
          border: none;
          padding-bottom: 0;
        }

        .el-calendar__button-group {
          text-align: center;
          background: transparent;

          .el-button-group>.el-button {
            color: #1f2122;
            border: none;
            background: rgba(255, 255, 255, .1);
          }
        }

        .el-calendar-table {
          thead th {
            color: #32C5FF;
            font-size: 12px;
            font-weight: bold;
          }

          .el-calendar-day {
            height: 40px;
            text-align: center;
          }

          td {
            border: none;
          }
        }
      }

    }

    .bot-box {
      width: 340px;
      border-radius: 16px;
      padding-top: 0;
      box-sizing: border-box;
      background: #fff;
      position: relative;
      overflow: hidden;

      .title {
        font-weight: bold;
        color: #32C5FF;
        position: relative;
        width: 100%;
        height: 60px;
        padding: 20px;
        padding-bottom: 0;
        background: linear-gradient(169deg, #E2F7FF 0%, #FFFFFF 100%);

        span {
          position: absolute;
          display: flex;
          right: 20px;
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #32C5FF;
          bottom: 20px;
          cursor: pointer;
        }
      }

      .hot-list {
        width: calc(100% - 40px);
        margin: 0 auto;
        padding-top: 20px;
        padding-bottom: 20px;

        .list-item {
          margin-bottom: 18px;
          cursor: pointer;
          display: flex;
          align-items: center;

          .index-box {
            display: inline-block;
            text-align: center;
            width: 20px;
            font-family: Tensentype-RuiHeiJ, Tensentype-RuiHeiJ;
            font-weight: normal;
            font-size: 18px;
            color: #999999;
            font-weight: bold;
          }

          .txt {
            max-width: calc(100% - 34px);
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            margin-left: 10px;
            font-family: PingFangSC, PingFang SC;
            font-weight: 400;
            font-size: 16px;
            color: #222222;
            line-height: 22px;
            text-align: left;
            font-style: normal;
          }

          &:hover {
            .txt {
              color: #32C5FF;
            }
          }
        }
      }
    }
  }

  :deep(.left) {
    width: calc(100% - 360px);
    border: none;
    border-radius: 16px;
    overflow: hidden;
    background: linear-gradient(177deg, #f3fcff 0%, #FFFFFF 10%);

    .el-table {
      th.el-table__cell {
        background-color: rgba(50, 197, 255, 0.08) !important;
        font-size: 13px;
      }

      td {
        height: 54px;
      }
    }
    .el-card__header {
      font-family: PingFangSC, PingFang SC;
      font-weight: 600;
      font-size: 20px;
      color: #222222;
      line-height: 28px;
      text-align: left;
      font-style: normal;
      border: none;
      padding-bottom: 0;
    }
  }
}

.el-input__wrapper {
  background-color: #F8F8F8;
}

.index-announcement {
  background-color: rgba(247, 247, 247, 1);
  display: flex;
  justify-content: center;
  margin-top: 20px;

  .no-border {
    border: none;
  }
}

.el-table {
  th {
    word-break: break-word;
    background-color: #033e7c !important;
    color: #ffff;
    height: 40px;
    font-weight: 700;
    font-size: 14px;
  }
}
</style>

<!-- npm install ace-builds@1.4.13 -->